using System;
using Game500.Client.Src.Logic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Game500.Client.Src
{
  public class Plane : Renderable
  {
    private readonly ArrowDrawer myArrowDrawer;
    private readonly Color myColor;
    private readonly ObjectManager myObjectManager;
    private readonly ShadowDrawer myShadowDrawer;
    private readonly Texture2D myTexture;

    public Plane(Texture2D planeTexture, ResourceManager resource, ObjectManager objectManager, Color color)
    {
      myObjectManager = objectManager;
      myShadowDrawer = new ShadowDrawer(resource);
      myArrowDrawer = new ArrowDrawer(resource);
      myTexture = planeTexture;
      myColor = color;
      IsOtherPlayer = true;
    }

    private Plane(Plane original) : base(original)
    {
      myArrowDrawer = original.myArrowDrawer;
      myShadowDrawer = original.myShadowDrawer;
      myTexture = original.myTexture;
      myColor = original.myColor;
      myObjectManager = original.myObjectManager;

      IsOtherPlayer = original.IsOtherPlayer;
    }

    public bool IsOtherPlayer { private get; set; }

    public int Score { get; set; }

    public override Renderable Clone()
    {
      return new Plane(this);
    }

    public override void Render(Renderer renderer)
    {
      if (!Visible) return;
      if (IsOtherPlayer) myArrowDrawer.DrawArrow(myObjectManager.Player.Position, Position, renderer, myColor);
      renderer.RenderSprite(myTexture, Position, Origin, Scale, rotation: Rotation);
      myShadowDrawer.DrawShadow(this, renderer);

      var rot = Rotation - Math.PI / 2;
      if (ScaleY < 0) rot += Math.PI;

      Vector2 v = 50.0f * new Vector2((float)Math.Cos(rot), -(float)Math.Sin(rot)) + new Vector2(Position.X, Position.Y);
      renderer.DrawString(Score.ToString(), v, myColor);
    }
  }
}